package com.dst.controller;

import com.dst.dao.BrandMapper;
import com.dst.entity.Brand;
import com.dst.service.BrandService;

import com.dst.service.PhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    @Qualifier("brandService")
    private BrandService brandService;
    @Autowired
    @Qualifier("phoneService")
    private PhoneService phoneService;
    @RequestMapping("/selectAll")
    public String selectAll(Model model){
        List<Brand> brands = brandService.selectAll();
        model.addAttribute("brands",brands);
        return "/addphone.jsp";
    }
    @RequestMapping("/selectAllBrandController")
    public String selectAllBrandController(Model model){
        List<Brand> brands = brandService.selectAll0001();
        model.addAttribute("brands",brands);
        return "/brand-list.jsp";
    }
    @RequestMapping("/deleteByIdBrandController")
    public String deleteByIdBrandController(int id){
        brandService.delete(id);
        phoneService.deletePhone(id);
        return "redirect:selectAllBrandController.do";
    }
    @RequestMapping("/addBrandController")
    public String addBrandController(Brand brand){
        brandService.add(brand);
        return "redirect:selectAllBrandController.do";
    }
}
